<script lang="ts" setup>
import type { homePageDocApiRowsItem } from '@/types/home'
import { useLike } from '@/composable/index'
// import { likePost } from '@/api/home'
// import { ref } from 'vue'
defineProps<{
  item: homePageDocApiRowsItem
}>()

/*
关注
关注与取消关注是同一接口
1:定义接口api
2:导入与调用
3：处理类型
4：调用成功，关注的值要0==>1  /  1==>0
5:加入loading
*/
// const loading = ref(false)
// const likeEvent = async (item: homePageDocApiRowsItem) => {
//   loading.value = true
//   try {
//     await likePost({
//       type: 'doc',
//       id: item.id
//     })
//     // 1==> 0   0==>1
//     item.likeFlag = item.likeFlag === 1 ? 0 : 1
//     // item.likeFlag = (1 - item.likeFlag) as 0 | 1
//   } finally {
//     loading.value = false
//   }
// }
const { loading, likeEvent } = useLike()
</script>
<template>
  <div class="doctor-card">
    <van-image round :src="item.avatar" />
    <p class="name">{{ item.name }}</p>
    <p class="van-ellipsis">{{ item.hospitalName }} {{ item.depName }}</p>
    <p>{{ item.positionalTitles }}</p>
    <van-button :loading="loading" round size="small" type="primary" @click="likeEvent(item)">{{
      item.likeFlag === 1 ? '已关注' : '+ 关注'
    }}</van-button>
  </div>
</template>
<style scoped lang="scss">
.doctor-card {
  width: 135px;
  height: 190px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0px 0px 11px 0px rgba(229, 229, 229, 0.2);
  text-align: center;
  padding: 15px;
  margin-left: 15px;
  display: inline-block;
  box-sizing: border-box;
  > .van-image {
    width: 58px;
    height: 58px;
    vertical-align: top;
    border-radius: 50%;
    margin: 0 auto 8px;
  }
  > p {
    margin-bottom: 0;
    font-size: 11px;
    color: var(--cp-tip);
    &.name {
      font-size: 13px;
      color: var(--cp-text1);
      margin-bottom: 5px;
    }
  }
  > .van-button {
    padding: 0 12px;
    height: 28px;
    margin-top: 8px;
    width: 72px;
  }
}
</style>
